﻿using System;
using System.Collections.Generic;

using DataFactory.Cms;
using IDAL.Cms;
using Model.Cms;
using Model.Base;
namespace BLL.Cms
{
    /// <summary>
    /// 业务层，内容管理，广告
    /// </summary>
    public class BlockBLL
    {
        /// <summary>
        /// 广告对象映射
        /// </summary>
        private IBlock dal = DataAccess.CreateBlock();

        /// <summary>
        /// 新增区块
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int InsertBlock(BlockInfo info)
        {
            return dal.InsertBlock(info);
        }
        /// <summary>
        /// 修改区块
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool UpdateBlock(BlockInfo info)
        {
            return dal.UpdateBlock(info);
        }

        /// <summary>
        /// 删除广告
        /// </summary>
        /// <param name="blockID"></param>
        /// <returns></returns>
        public bool DeleteBlock(int blockID) 
        {
            return dal.DeleteBlock(blockID, "", 0);
        }

        /// <summary>
        /// 获取区块
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BlockInfo GetBlockByID(int id)
        {
            return dal.GetBlockByID(id);
        }

        /// <summary>
        /// 前台按点位获取指定数目的广告
        /// </summary>
        /// <param name="reviewAuth"></param>
        /// <param name="blockCategory"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public IList<BlockInfo> FrontListByTerm(bool reviewAuth, int blockCategoryID, string blockCategoryLabel, int top)
        {
            BlockCondition condition = new BlockCondition();
            if (!reviewAuth)
            {
                condition.IsOnline = "y";
                condition.TimeType = ListTime.Online;
            }
            condition.BlockCategoryID = blockCategoryID;
            condition.BlockCategoryLabel = blockCategoryLabel;
            condition.Top = top;
            condition.OrderBy = "[Rank] DESC, AddTime DESC";
            return dal.ListBlock(condition);
        }

        /// <summary>
        /// 后台广告位列表
        /// </summary>
        /// <param name="blockCategory"></param>
        /// <param name="blockType"></param>
        /// <param name="isonline"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<BlockInfo> BackList(int blockCategory, string blockType, string isonline, int pageIndex, int pageSize, out int recordCount)
        {
            BlockCondition condition = new BlockCondition();
            condition.TimeType = ListTime.Timeline;
            condition.BlockCategoryID = blockCategory;
            condition.BlockType = blockType;
            condition.IsOnline = isonline;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "AddTime DESC";
            return dal.ListBlock(condition, out recordCount);
        }
    }
}
